<template>
	<view>
		<u-navbar title=" " titleStyle="color:#fff;" titleWidth="600rpx" :placeholder="true" leftIconColor="#fff" :autoBack="true" bgColor="rgba(0,0,0,0)">
			<view class="fans_tabs" slot="center">
				<view class="item" :class="tabsIndex == 0?'hover':''" @click="clickTabs(0)">
					场景
				</view>
				<view class="item" :class="tabsIndex == 1?'hover':''" @click="clickTabs(1)">
					用户
				</view>
			</view>
		</u-navbar>
		
		<!-- <u-empty v-if="listData.length == 0" mode="data" marginTop="200rpx" icon="/static/img/ico_none.png" ></u-empty> -->
		<!-- 场景 -->
		<view class="scene_list" v-if="tabsIndex == 0">
			<view class="item" v-for="(item,index) in listData" :key="index" @click="clickGotoHome(item.live_id)">
				<image class="ph" :src="item.live_info.file" mode="aspectFill"></image>
				<view class="name">
					{{item.live_info.name}}
				</view>
			</view>
		</view>
		
		<!-- 用户 -->
		<view class="history_list" v-if="tabsIndex == 1">
			<view class="item" v-for="(item,index) in listData" :key="index">
				<navigator style="display: flex;align-items: center;" :url="'/pages/homepage/userpage?id='+item.user_info.id" hover-class="none">
					<image class="ph" :src="item.user_info.avatar" mode="aspectFill"></image>
					<view class="info">
						<view class="name">
							{{item.user_info.nickname}}
						</view>
						<view class="text">
							推氪号:{{item.user_info.t_id}}
						</view>
					</view>
				</navigator>
				<view class="btn" v-if="item.is_follow == 0" @click="clickLike(0,item.user_info.id)">
					关注
				</view>
				<view class="btn hover" v-if="item.is_follow == 1" @click="clickLike(1,item.user_info.id)">
					已关注
				</view>
				
			</view>
			<!-- <view class="item">
				<image class="ph" src="../../static/img/head1.png" mode="aspectFill"></image>
				<view class="info">
					<view class="name">
						Suny-孙
					</view>
					<view class="text">
						推氪号:223463
					</view>
				</view>
				<view class="btn hover">
					已关注
				</view>
			</view> -->
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabsIndex: 0,
				userId:'',
				listData: []
			}
		},
		onLoad(opt) {
			if(opt.tabsIndex){
				this.tabsIndex = opt.tabs
			}
			this.userId = uni.getStorageSync('userId');
			this.getViewList(0)
		},
		methods: {
			clickGotoHome(id){
				uni.reLaunch({
					url: '/pages/index/index?liveId='+id
				});
			},
			// 点击/取消添加关注
			clickLike(index,id){
				if(index == 1)
				{
					uni.$u.http.post('api/speed_follow_cancel/'+this.userId, {follow_id: id} ).then(res => {
						console.log('取消关注-----',res.data)
						this.getViewList(1)
					}).catch(err => {
						console.log(err)
					})
				}
				else if(index == 0){
					uni.$u.http.post('api/speed_follow_add/'+this.userId, {follow_id: id} ).then(res => {
						console.log('添加关注-----',res.data)
						this.getViewList(1)
					}).catch(err => {
						console.log(err)
					})
				}
			},
			getViewList(index){
				uni.$u.http.get('/api/speed_view_list/'+this.userId+'?from=miniprogram&count=999&only_user='+index).then(res => {
					console.log('观看历史-----',res.data)
					this.listData = res.data.data
				}).catch(err => {
					console.log(err)
				})
			},
			clickTabs(index){
				this.listData = []
				this.tabsIndex = index
				this.getViewList(index)
			}
		}
	}
</script>

<style lang="scss" scoped>
.fans_tabs{
	display: flex;
	align-items: center;
	justify-content: space-between;
	.item{
		padding:10rpx 20rpx;
		font-size: 30rpx;
		font-weight: normal;
		line-height: 50rpx;
		text-align: justify;
		color: #9B9B9B;
		text-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2613);
		position: relative;
		&.hover{
			color:#fff;
			font-weight: 600;
			&::after{
				content: '';
				position: absolute;
				left:50%;
				bottom: 0;
				width: 40rpx;
				height: 6rpx;
				margin-left: -20rpx;
				border-radius: 3rpx;
				background: #FFB200;
			}
		}
		&:last-child{
			margin-left: 80rpx;
		}
	}
}
.search{
	margin: 40rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 70rpx;
	border-radius: 40rpx;
	background: #2C2C2C;
	box-shadow: 4rpx 4rpx 60rpx 0rpx rgba(0, 0, 0, 0.05);
	padding:0 30rpx;
	.ico_ss{
		flex-shrink: 0;
		width: 36rpx;
		height: 36rpx;
		margin-right: 15rpx;
	}
	.input_ss{
		width: 100%;
		font-size: 24rpx;
		font-weight: normal;
		line-height: 48rpx;
		text-align: justify;
		color: #979797;
	}
}
.list_title{
	font-size: 28rpx;
	font-weight: normal;
	line-height: 48rpx;
	text-align: justify;
	color: #FFFFFF;
	padding:0 40rpx;
}
.history_list{
	padding:20rpx 0;
	.item{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding:20rpx 40rpx;
		.info{
			width: 100%;
		}
		.ph{
			flex-shrink: 0;
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			margin-right: 28rpx;
		}
		.name{
			width: 100%;
			font-size: 26rpx;
			font-weight: 600;
			line-height: 40rpx;
			color: #FFFFFF;
		}
		.text{
			font-size: 22rpx;
			font-weight: normal;
			line-height: 32rpx;
			color: #A7A7A7;
			margin-top: 6rpx;
		}
		.btn{
			flex-shrink: 0;
			width: 120rpx;
			height: 50rpx;
			border-radius: 8rpx;
			background: #FFB200;
			text-align: center;
			font-size: 24rpx;
			font-weight: 500;
			color: #1F1F1F;
			line-height: 50rpx;
			&.hover{
				background: #484848;
				color:#fff;
			}
		}
	}
}

.scene_list{
	display: flex;
	align-items: flex-start;
	flex-wrap: wrap;
	padding:0 30rpx 0 10rpx;
	.item{
		width: 204rpx;
		height: 360rpx;
		position: relative;
		margin-top: 30rpx;
		margin-left: 30rpx;
		.lock{
			position: absolute;
			left:0;
			right: 0;
			top:0;
			bottom: 0;
			z-index: 9;
			display: flex;
			align-items: center;
			justify-content: center;
			.ico_8{
				width: 36rpx;
			}
		}
		.ph{
			display: block;
			width: 100%;
			height: 360rpx;
			border-radius: 10rpx;
			background: #484848;
		}
		.name{
			position: absolute;
			left:0;
			bottom: 0;
			right: 0;
			font-size: 22rpx;
			font-weight: normal;
			line-height: 32rpx;
			text-align: justify;
			color: #FFFFFF;
			text-shadow: 0px 2rpx 4rpx rgba(0, 0, 0, 0.5);
			padding:10rpx;
		}
	}
}

</style>
